package exception;

/**
 * 异常处理机制
 */
public class TryCatchDemo {
    public static void main(String[] args) {
        System.out.println("程序开始");
        String line = "";
        String line1 = "a";
        try {
            System.out.println(Integer.parseInt(line1)); //转换为数字
            System.out.println(line1.charAt(0));
            System.out.println(line1.length());
            System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!");
        }catch (NullPointerException|StringIndexOutOfBoundsException e){
            System.out.println("出现了下标越界或空指针异常！！！");
        }catch (Exception e){
            System.out.println("出现一个未知错误");
        }
        /*}catch (NullPointerException e){
            System.out.println("出现空指针异常，并解决了");
        }catch (StringIndexOutOfBoundsException e){
            System.out.println("字符串下标越界异常，并解决了");
        }*/
        System.out.println("程序结束");


    }
}
